package com.code.controller;

import com.code.pojo.req.UploadCompleteRequest;
import com.code.pojo.req.UploadInitRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/upload")
public class UploadController {

    private static final Logger log = LoggerFactory.getLogger(UploadController.class);

    @PostMapping("/init")
    public ResponseEntity<?> initUpload(@RequestBody UploadInitRequest uploadInitRequest, HttpServletRequest request) {
        System.out.println(request);
        // 实现初始化逻辑
        log.debug("进来了");
        return null;
    }

    @PostMapping("/chunk")
    public ResponseEntity<?> uploadChunk(
            @RequestParam("file") MultipartFile file,
            @RequestParam Integer chunkNumber,
            @RequestParam String fileHash,
            @RequestParam String uploadId
    ) {
        // 处理分片上传
        return null;
    }

    @PostMapping("/complete")
    public ResponseEntity<?> completeUpload(@RequestBody UploadCompleteRequest request) {
        // 合并分片并返回结果
        return null;
    }
}